package br.ufrgs.inf.cwsmart.impl.description;

import org.uc3m.verbus.bpel.BPELException;
import org.uc3m.verbus.bpel.model.Activity;
import org.uc3m.verbus.bpel.parser.Parser;
import org.uc3m.verbus.bpel.util.BPWSUtil;

import br.ufrgs.inf.cwsmart.core.CWSType;
import br.ufrgs.inf.cwsmart.description.CWSDescription;

/**
 * An implementation class for the BPEL CWSs.
 * 
 * @author Rodrigo S Lumertz
 *
 */
public class BPELDescription extends CWSDescription {	

	public BPELDescription(String cwsPath, String language, String... wsdlPaths) {
		super(cwsPath, language, wsdlPaths);		
	}

	@Override
	public void parse() {
			
		org.uc3m.verbus.util.Logger.logger.setLogLevel(org.uc3m.verbus.util.Logger.MIN_DEBUG_LEVEL);
		
		Parser parser = null;

        try {
        	parser = new Parser(this.cwsPath, (String[])this.wsdlPaths.toArray());
        	
        	System.out.println("cws name: " + parser.getProcess().getName().toString());
        	System.out.println("language: " + this.language);
        	
        	//getting the cws id
        	this.cwsId = parser.getProcess().getTargetNamespace() + parser.getProcess().getName();

        	Activity activity = parser.getProcess().getActivity();      
        	
        	//getting the execution type
        	if(activity != null && BPWSUtil.getActivityType(activity) == BPWSUtil.ACT_SEQUENCE)        		
        		this.cwsType = CWSType.PROACTIVE;
        	else if (activity != null)
        		this.cwsType = CWSType.REACTIVE;
           
        	System.out.println("TODO: [impl] get some more informations...");
        } catch (BPELException ex) {
            ex.printStackTrace();
            System.exit(1);
        }
	}

}
